#include "zluaobj.h"
#include "zobj.h"
/*
void * ZObj::operator new(size_t size)
{
return malloc(size);
}
void ZObj::operator delete(void * mem)
{
if (mem) free(mem);
}
*/
static int ref_gc (lua_State *L) 
{
	ZObj **f = (ZObj **)lua_touserdata(L,1);
	/* ignore closed files */
	if (f != NULL && *f != NULL)
		(*f)->decRef();
	return 0;
}

static const luaL_Reg refgc[] = {
	{"__gc", ref_gc},
	{NULL, NULL}
};
void ZObj_lua_meta(struct lua_State* L)
{
	zlua_createmeta(L,ZLUA_TYPEDEF(ZObj),refgc);
}

void ZObj::release()
{
	if (!isClosed())
		close();
	delete this;
};
